const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
// 最新的 vue-loader 中，VueLoaderPlugin 插件的位置有所改变
const { VueLoaderPlugin } = require("vue-loader");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");

module.exports = {
  mode: "development", // 环境模式
  entry: path.resolve(__dirname, "./src/main.js"), // 打包入口
  output: {
    path: path.resolve(__dirname, "dist"), // 打包出口
    filename: "[name].[hash:6].js", // 打包完的静态资源文件名
  },
  devServer: {
    contentBase: "dist",
    hot: true,
    port: 9000,
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/, // 不编译node_modules下的文件
        loader: "babel-loader",
      },
      {
        test: /.vue$/,
        // vue-loader 必须安装最新的 vue-loader@next
        // vue-template-compiler 需要替换成 @vue/compiler-sfc@next
        use: "vue-loader",
      },
      {
        test: /.css$/,
        use: ["style-loader", "css-loader"],
      },
    ],
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      template: "./index.html",
      filename: "index.html",
      title: "Hello Vue 3",
    }),
    new VueLoaderPlugin(),
  ],
};
